package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceReason;
import com.ruoyi.service.service.IServiceReasonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 锁定原因Controller
 * 
 * @author ZDL
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/service/reason")
public class ServiceReasonController extends BaseController
{
    @Autowired
    private IServiceReasonService serviceReasonService;

    /**
     * 查询锁定原因列表
     */
    @PreAuthorize("@ss.hasPermi('service:reason:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceReason serviceReason)
    {
        startPage();
        List<ServiceReason> list = serviceReasonService.selectServiceReasonList(serviceReason);
        return getDataTable(list);
    }

    /**
     * 导出锁定原因列表
     */
    @PreAuthorize("@ss.hasPermi('service:reason:export')")
    @Log(title = "锁定原因", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceReason serviceReason)
    {
        List<ServiceReason> list = serviceReasonService.selectServiceReasonList(serviceReason);
        ExcelUtil<ServiceReason> util = new ExcelUtil<ServiceReason>(ServiceReason.class);
        util.exportExcel(response, list, "锁定原因数据");
    }

    /**
     * 获取锁定原因详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:reason:query')")
    @GetMapping(value = "/{reasonId}")
    public AjaxResult getInfo(@PathVariable("reasonId") Long reasonId)
    {
        return success(serviceReasonService.selectServiceReasonByReasonId(reasonId));
    }

    /**
     * 新增锁定原因
     */
    @PreAuthorize("@ss.hasPermi('service:reason:add')")
    @Log(title = "锁定原因", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceReason serviceReason)
    {
        return toAjax(serviceReasonService.insertServiceReason(serviceReason));
    }

    /**
     * 修改锁定原因
     */
    @PreAuthorize("@ss.hasPermi('service:reason:edit')")
    @Log(title = "锁定原因", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceReason serviceReason)
    {
        return toAjax(serviceReasonService.updateServiceReason(serviceReason));
    }

    /**
     * 删除锁定原因
     */
    @PreAuthorize("@ss.hasPermi('service:reason:remove')")
    @Log(title = "锁定原因", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reasonIds}")
    public AjaxResult remove(@PathVariable Long[] reasonIds)
    {
        return toAjax(serviceReasonService.deleteServiceReasonByReasonIds(reasonIds));
    }
}
